package test.demo.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import test.demo.service.EventStreamService;

@Slf4j
@RestController
@RequestMapping("/chat")
public class ChatController {

    @Autowired
    private EventStreamService eventStreamService;

    /**
     * 前端传入msgId，ollma接口没有生成msgId，一条msgId在前端需要多次更新，所以不能少
     * @param query
     * @param msgId
     * @return
     */
    @RequestMapping(value = "/ai", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> streamEvents(@RequestParam String query, String msgId) {
        return eventStreamService.getEventStream(query, msgId);
    }

}
